home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Interfaces&Libraries / Universal / Interfaces / CIncludes / SCSI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  51.2 KB  |  1,060 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        SCSI.h
  3.  
  4.      Contains:    SCSI Family Interfaces.
  5.  
  6.      Version:    Technology:    SCSI 4.3
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1986-1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __SCSI__
  18. #define __SCSI__
  19.  
  20. #ifndef __MACTYPES__
  21. #include <MacTypes.h>
  22. #endif
  23. #ifndef __MIXEDMODE__
  24. #include <MixedMode.h>
  25. #endif
  26.  
  27.  
  28.  
  29. #if PRAGMA_ONCE
  30. #pragma once
  31. #endif
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36.  
  37. #if PRAGMA_IMPORT
  38. #pragma import on
  39. #endif
  40.  
  41. #if PRAGMA_STRUCT_ALIGN
  42.     #pragma options align=mac68k
  43. #elif PRAGMA_STRUCT_PACKPUSH
  44.     #pragma pack(push, 2)
  45. #elif PRAGMA_STRUCT_PACK
  46.     #pragma pack(2)
  47. #endif
  48.  
  49. /* SCSI Manager errors. These are generated by Inside Mac IV calls only. */
  50.  
  51. enum {
  52.     scCommErr                    = 2,                            /* communications error, operation timeout */
  53.     scArbNBErr                    = 3,                            /* arbitration timeout waiting for not BSY */
  54.     scBadParmsErr                = 4,                            /* bad parameter or TIB opcode */
  55.     scPhaseErr                    = 5,                            /* SCSI bus not in correct phase for attempted operation */
  56.     scCompareErr                = 6,                            /* data compare error */
  57.     scMgrBusyErr                = 7,                            /* SCSI Manager busy  */
  58.     scSequenceErr                = 8,                            /* attempted operation is out of sequence */
  59.     scBusTOErr                    = 9,                            /* CPU bus timeout */
  60.     scComplPhaseErr                = 10                            /* SCSI bus wasn't in Status phase */
  61. };
  62.  
  63. /* TIB opcodes */
  64.  
  65. enum {
  66.     scInc                        = 1,
  67.     scNoInc                        = 2,
  68.     scAdd                        = 3,
  69.     scMove                        = 4,
  70.     scLoop                        = 5,
  71.     scNop                        = 6,
  72.     scStop                        = 7,
  73.     scComp                        = 8
  74. };
  75.  
  76. /* Signatures */
  77.  
  78. enum {
  79.     sbSIGWord                    = 0x4552,                        /* signature word for Block 0 ('ER') */
  80.     sbMac                        = 1,                            /* system type for Mac */
  81.     pMapSIG                        = 0x504D,                        /* partition map signature ('PM') */
  82.     pdSigWord                    = 0x5453
  83. };
  84.  
  85.  
  86. enum {
  87.     oldPMSigWord                = pdSigWord,
  88.     newPMSigWord                = pMapSIG
  89. };
  90.  
  91. /* Driver Descriptor Map */
  92.  
  93. struct Block0 {
  94.     unsigned short                     sbSig;                        /* unique value for SCSI block 0 */
  95.     unsigned short                     sbBlkSize;                    /* block size of device */
  96.     unsigned long                     sbBlkCount;                    /* number of blocks on device */
  97.     unsigned short                     sbDevType;                    /* device type */
  98.     unsigned short                     sbDevId;                    /* device id */
  99.     unsigned long                     sbData;                        /* not used */
  100.     unsigned short                     sbDrvrCount;                /* driver descriptor count */
  101.     unsigned long                     ddBlock;                    /* 1st driver's starting block */
  102.     unsigned short                     ddSize;                        /* size of 1st driver (512-byte blks) */
  103.     unsigned short                     ddType;                        /* system type (1 for Mac+) */
  104.     unsigned short                     ddPad[243];                    /* ARRAY[0..242] OF INTEGER; not used */
  105. };
  106. typedef struct Block0                    Block0;
  107. /* Driver descriptor */
  108.  
  109. struct DDMap {
  110.     unsigned long                     ddBlock;                    /* 1st driver's starting block */
  111.     unsigned short                     ddSize;                        /* size of 1st driver (512-byte blks) */
  112.     unsigned short                     ddType;                        /* system type (1 for Mac+) */
  113. };
  114. typedef struct DDMap                    DDMap;
  115. /* Partition Map Entry */
  116.  
  117. struct Partition {
  118.     unsigned short                     pmSig;                        /* unique value for map entry blk */
  119.     unsigned short                     pmSigPad;                    /* currently unused */
  120.     unsigned long                     pmMapBlkCnt;                /* # of blks in partition map */
  121.     unsigned long                     pmPyPartStart;                /* physical start blk of partition */
  122.     unsigned long                     pmPartBlkCnt;                /* # of blks in this partition */
  123.     unsigned char                     pmPartName[32];                /* ASCII partition name */
  124.     unsigned char                     pmParType[32];                /* ASCII partition type */
  125.     unsigned long                     pmLgDataStart;                /* log. # of partition's 1st data blk */
  126.     unsigned long                     pmDataCnt;                    /* # of blks in partition's data area */
  127.     unsigned long                     pmPartStatus;                /* bit field for partition status */
  128.     unsigned long                     pmLgBootStart;                /* log. blk of partition's boot code */
  129.     unsigned long                     pmBootSize;                    /* number of bytes in boot code */
  130.     unsigned long                     pmBootAddr;                    /* memory load address of boot code */
  131.     unsigned long                     pmBootAddr2;                /* currently unused */
  132.     unsigned long                     pmBootEntry;                /* entry point of boot code */
  133.     unsigned long                     pmBootEntry2;                /* currently unused */
  134.     unsigned long                     pmBootCksum;                /* checksum of boot code */
  135.     unsigned char                     pmProcessor[16];            /* ASCII for the processor type */
  136.     unsigned short                     pmPad[188];                    /* ARRAY[0..187] OF INTEGER; not used */
  137. };
  138. typedef struct Partition                Partition;
  139. /* TIB instruction */
  140.  
  141. struct SCSIInstr {
  142.     unsigned short                     scOpcode;
  143.     long                             scParam1;
  144.     long                             scParam2;
  145. };
  146. typedef struct SCSIInstr                SCSIInstr;
  147. /* SCSI Phases (used by SIMs to support the Original SCSI Manager */
  148.  
  149. enum {
  150.     kDataOutPhase                = 0,                            /* Encoded MSG, C/D, I/O bits */
  151.     kDataInPhase                = 1,
  152.     kCommandPhase                = 2,
  153.     kStatusPhase                = 3,
  154.     kPhaseIllegal0                = 4,
  155.     kPhaseIllegal1                = 5,
  156.     kMessageOutPhase            = 6,
  157.     kMessageInPhase                = 7,
  158.     kBusFreePhase                = 8,                            /* Additional Phases */
  159.     kArbitratePhase                = 9,
  160.     kSelectPhase                = 10,
  161.     kMessageInPhaseNACK            = 11                            /* Message In Phase with ACK hanging on the bus */
  162. };
  163.  
  164.  
  165. EXTERN_API( OSErr )
  166. SCSIReset                        (void)                                                        TWOWORDINLINE(0x4267, 0xA815);
  167.  
  168. EXTERN_API( OSErr )
  169. SCSIGet                            (void)                                                        THREEWORDINLINE(0x3F3C, 0x0001, 0xA815);
  170.  
  171. EXTERN_API( OSErr )
  172. SCSISelect                        (short                     targetID)                            THREEWORDINLINE(0x3F3C, 0x0002, 0xA815);
  173.  
  174. EXTERN_API( OSErr )
  175. SCSICmd                            (Ptr                     buffer,
  176.                                  short                     count)                                THREEWORDINLINE(0x3F3C, 0x0003, 0xA815);
  177.  
  178. EXTERN_API( OSErr )
  179. SCSIRead                        (Ptr                     tibPtr)                                THREEWORDINLINE(0x3F3C, 0x0005, 0xA815);
  180.  
  181. EXTERN_API( OSErr )
  182. SCSIRBlind                        (Ptr                     tibPtr)                                THREEWORDINLINE(0x3F3C, 0x0008, 0xA815);
  183.  
  184. EXTERN_API( OSErr )
  185. SCSIWrite                        (Ptr                     tibPtr)                                THREEWORDINLINE(0x3F3C, 0x0006, 0xA815);
  186.  
  187. EXTERN_API( OSErr )
  188. SCSIWBlind                        (Ptr                     tibPtr)                                THREEWORDINLINE(0x3F3C, 0x0009, 0xA815);
  189.  
  190. EXTERN_API( OSErr )
  191. SCSIComplete                    (short *                stat,
  192.                                  short *                message,
  193.                                  unsigned long             wait)                                THREEWORDINLINE(0x3F3C, 0x0004, 0xA815);
  194.  
  195. EXTERN_API( short )
  196. SCSIStat                        (void)                                                        THREEWORDINLINE(0x3F3C, 0x000A, 0xA815);
  197.  
  198. EXTERN_API( OSErr )
  199. SCSISelAtn                        (short                     targetID)                            THREEWORDINLINE(0x3F3C, 0x000B, 0xA815);
  200.  
  201. EXTERN_API( OSErr )
  202. SCSIMsgIn                        (short *                message)                            THREEWORDINLINE(0x3F3C, 0x000C, 0xA815);
  203.  
  204. EXTERN_API( OSErr )
  205. SCSIMsgOut                        (short                     message)                            THREEWORDINLINE(0x3F3C, 0x000D, 0xA815);
  206.  
  207.  
  208.  
  209. enum {
  210.     scsiVERSION                    = 43
  211. };
  212.  
  213.  
  214. /*
  215.  * SCSI Callback Procedure Prototypes. Several of these are only callable
  216.  * from SCSI Manager 4.3 SIM and XPT contexts. 
  217.  */
  218. typedef CALLBACK_API_C( void , AENCallbackProcPtr )(void );
  219. typedef CALLBACK_API_C( OSErr , SIMInitProcPtr )(Ptr SIMinfoPtr);
  220. typedef CALLBACK_API_C( void , SIMActionProcPtr )(void *scsiPB, Ptr SIMGlobals);
  221. typedef CALLBACK_API_C( void , SCSIProcPtr )(void );
  222. typedef CALLBACK_API_C( void , SCSIMakeCallbackProcPtr )(void *scsiPB);
  223. /* SCSIInterruptPollProcPtr is obsolete (use SCSIInterruptProcPtr) but still here for compatibility */
  224. typedef CALLBACK_API_C( long , SCSIInterruptPollProcPtr )(Ptr SIMGlobals);
  225. typedef CALLBACK_API_C( long , SCSIInterruptProcPtr )(Ptr SIMGlobals);
  226. typedef STACK_UPP_TYPE(AENCallbackProcPtr)                         AENCallbackUPP;
  227. typedef STACK_UPP_TYPE(SIMInitProcPtr)                             SIMInitUPP;
  228. typedef STACK_UPP_TYPE(SIMActionProcPtr)                         SIMActionUPP;
  229. typedef STACK_UPP_TYPE(SCSIProcPtr)                             SCSIUPP;
  230. typedef STACK_UPP_TYPE(SCSIMakeCallbackProcPtr)                 SCSIMakeCallbackUPP;
  231. typedef STACK_UPP_TYPE(SCSIInterruptPollProcPtr)                 SCSIInterruptPollUPP;
  232. typedef STACK_UPP_TYPE(SCSIInterruptProcPtr)                     SCSIInterruptUPP;
  233. typedef CALLBACK_API( void , SCSICallbackProcPtr )(void *scsiPB);
  234. typedef STACK_UPP_TYPE(SCSICallbackProcPtr)                     SCSICallbackUPP;
  235. enum { uppAENCallbackProcInfo = 0x00000001 };                     /* no_return_value Func() */
  236. enum { uppSIMInitProcInfo = 0x000000E1 };                         /* 2_bytes Func(4_bytes) */
  237. enum { uppSIMActionProcInfo = 0x000003C1 };                     /* no_return_value Func(4_bytes, 4_bytes) */
  238. enum { uppSCSIProcInfo = 0x00000001 };                             /* no_return_value Func() */
  239. enum { uppSCSIMakeCallbackProcInfo = 0x000000C1 };                 /* no_return_value Func(4_bytes) */
  240. enum { uppSCSIInterruptPollProcInfo = 0x000000F1 };             /* 4_bytes Func(4_bytes) */
  241. enum { uppSCSIInterruptProcInfo = 0x000000F1 };                 /* 4_bytes Func(4_bytes) */
  242. enum { uppSCSICallbackProcInfo = 0x000000C0 };                     /* pascal no_return_value Func(4_bytes) */
  243. #define NewAENCallbackProc(userRoutine)                         (AENCallbackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAENCallbackProcInfo, GetCurrentArchitecture())
  244. #define NewSIMInitProc(userRoutine)                             (SIMInitUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSIMInitProcInfo, GetCurrentArchitecture())
  245. #define NewSIMActionProc(userRoutine)                             (SIMActionUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSIMActionProcInfo, GetCurrentArchitecture())
  246. #define NewSCSIProc(userRoutine)                                 (SCSIUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIProcInfo, GetCurrentArchitecture())
  247. #define NewSCSIMakeCallbackProc(userRoutine)                     (SCSIMakeCallbackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIMakeCallbackProcInfo, GetCurrentArchitecture())
  248. #define NewSCSIInterruptPollProc(userRoutine)                     (SCSIInterruptPollUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIInterruptPollProcInfo, GetCurrentArchitecture())
  249. #define NewSCSIInterruptProc(userRoutine)                         (SCSIInterruptUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIInterruptProcInfo, GetCurrentArchitecture())
  250. #define NewSCSICallbackProc(userRoutine)                         (SCSICallbackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSICallbackProcInfo, GetCurrentArchitecture())
  251. #define CallAENCallbackProc(userRoutine)                         CALL_ZERO_PARAMETER_UPP((userRoutine), uppAENCallbackProcInfo)
  252. #define CallSIMInitProc(userRoutine, SIMinfoPtr)                 CALL_ONE_PARAMETER_UPP((userRoutine), uppSIMInitProcInfo, (SIMinfoPtr))
  253. #define CallSIMActionProc(userRoutine, scsiPB, SIMGlobals)         CALL_TWO_PARAMETER_UPP((userRoutine), uppSIMActionProcInfo, (scsiPB), (SIMGlobals))
  254. #define CallSCSIProc(userRoutine)                                 CALL_ZERO_PARAMETER_UPP((userRoutine), uppSCSIProcInfo)
  255. #define CallSCSIMakeCallbackProc(userRoutine, scsiPB)             CALL_ONE_PARAMETER_UPP((userRoutine), uppSCSIMakeCallbackProcInfo, (scsiPB))
  256. #define CallSCSIInterruptPollProc(userRoutine, SIMGlobals)         CALL_ONE_PARAMETER_UPP((userRoutine), uppSCSIInterruptPollProcInfo, (SIMGlobals))
  257. #define CallSCSIInterruptProc(userRoutine, SIMGlobals)             CALL_ONE_PARAMETER_UPP((userRoutine), uppSCSIInterruptProcInfo, (SIMGlobals))
  258. #define CallSCSICallbackProc(userRoutine, scsiPB)                 CALL_ONE_PARAMETER_UPP((userRoutine), uppSCSICallbackProcInfo, (scsiPB))
  259. /* SCSI Manager 4.3 function codes */
  260.  
  261. enum {
  262.     SCSINop                        = 0x00,                            /* Execute nothing                                         */
  263.     SCSIExecIO                    = 0x01,                            /* Execute the specified IO                             */
  264.     SCSIBusInquiry                = 0x03,                            /* Get parameters for entire path of HBAs                 */
  265.     SCSIReleaseQ                = 0x04,                            /* Release the frozen SIM queue for particular LUN         */
  266.     SCSIAbortCommand            = 0x10,                            /* Abort the selected Control Block                      */
  267.     SCSIResetBus                = 0x11,                            /* Reset the SCSI bus                                      */
  268.     SCSIResetDevice                = 0x12,                            /* Reset the SCSI device                                  */
  269.     SCSITerminateIO                = 0x13,                            /* Terminate any pending IO                              */
  270.     SCSIGetVirtualIDInfo        = 0x80,                            /* Find out which bus old ID is on                         */
  271.     SCSILoadDriver                = 0x82,                            /* Load a driver for a device ident                     */
  272.     SCSIOldCall                    = 0x84,                            /* XPT->SIM private call for old-API                     */
  273.     SCSICreateRefNumXref        = 0x85,                            /* Register a DeviceIdent to drvr RefNum xref             */
  274.     SCSILookupRefNumXref        = 0x86,                            /* Get DeviceIdent to drvr RefNum xref                     */
  275.     SCSIRemoveRefNumXref        = 0x87,                            /* Remove a DeviceIdent to drvr RefNum xref             */
  276.     SCSIRegisterWithNewXPT        = 0x88,                            /* XPT has changed - SIM needs to re-register itself     */
  277.     vendorUnique                = 0xC0                            /* 0xC0 thru 0xFF */
  278. };
  279.  
  280.  
  281. /* Allocation length defines for some of the fields */
  282.  
  283. enum {
  284.     handshakeDataLength            = 8,                            /* Handshake data length */
  285.     maxCDBLength                = 16,                            /* Space for the CDB bytes/pointer */
  286.     vendorIDLength                = 16                            /* ASCII string len for Vendor ID  */
  287. };
  288.  
  289. /* Define DeviceIdent structure */
  290.  
  291. struct DeviceIdent {
  292.     UInt8                             diReserved;                    /* reserved                 */
  293.     UInt8                             bus;                        /* SCSI - Bus Number        */
  294.     UInt8                             targetID;                    /* SCSI - Target SCSI ID    */
  295.     UInt8                             LUN;                        /* SCSI - LUN                  */
  296. };
  297. typedef struct DeviceIdent                DeviceIdent;
  298. /* Command Descriptor Block structure */
  299.  
  300. union CDB {
  301.     BytePtr                         cdbPtr;                        /* pointer to the CDB, or */
  302.     UInt8                             cdbBytes[16];                /* the actual CDB to send */
  303. };
  304. typedef union CDB                        CDB;
  305. typedef CDB *                            CDBPtr;
  306. /* Scatter/gather list element (Deprecated for MacOS8) */
  307.  
  308. struct SGRecord {
  309.     Ptr                             SGAddr;
  310.     UInt32                             SGCount;
  311. };
  312. typedef struct SGRecord                    SGRecord;
  313.  
  314. #define SCSIPBHdr                         \
  315.     struct SCSIHdr* qLink;                \
  316.     short            scsiReserved1;        \
  317.     UInt16            scsiPBLength;        \
  318.     UInt8            scsiFunctionCode;    \
  319.     UInt8            scsiReserved2;        \
  320.     volatile OSErr    scsiResult;            \
  321.     DeviceIdent        scsiDevice;            \
  322.     SCSICallbackUPP    scsiCompletion;        \
  323.     UInt32            scsiFlags;            \
  324.     UInt8 *            scsiDriverStorage;    \
  325.     Ptr                scsiXPTprivate;        \
  326.     long            scsiReserved3;
  327.  
  328.  
  329. struct SCSIHdr {
  330.     struct SCSIHdr *                qLink;                        /* (internal use, must be nil on entry)    */
  331.     short                             scsiReserved1;                /* ->     reserved for input                */
  332.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  333.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  334.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  335.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  336.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  337.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  338.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  339.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  340.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  341.     long                             scsiReserved3;                /* reserved                                */
  342. };
  343. typedef struct SCSIHdr                    SCSIHdr;
  344.  
  345. struct SCSI_PB {
  346.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  347.     short                             scsiReserved1;                /* ->     reserved for input                */
  348.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  349.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  350.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  351.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  352.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  353.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  354.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  355.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  356.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  357.     long                             scsiReserved3;                /* reserved                                */
  358. };
  359. typedef struct SCSI_PB                    SCSI_PB;
  360.  
  361. struct SCSI_IO {
  362.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  363.     short                             scsiReserved1;                /* ->     reserved for input                */
  364.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  365.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  366.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  367.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  368.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  369.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  370.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  371.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  372.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  373.     long                             scsiReserved3;                /* reserved                                */
  374.  
  375.     UInt16                             scsiResultFlags;            /* <- Flags which modify the scsiResult field        */
  376.     UInt16                             scsiReserved3pt5;            /* -> Reserved                                        */
  377.     BytePtr                         scsiDataPtr;                /* -> Pointer to the data buffer or the S/G list      */
  378.     UInt32                             scsiDataLength;                /* -> Data transfer length                            */
  379.     BytePtr                         scsiSensePtr;                /* -> Ptr to autosense data buffer                  */
  380.     UInt8                             scsiSenseLength;            /* -> size of the autosense buffer                     */
  381.     UInt8                             scsiCDBLength;                /* -> Number of bytes for the CDB                      */
  382.     UInt16                             scsiSGListCount;            /* -> num of scatter gather list entries              */
  383.     UInt32                             scsiReserved4;                /* <-     reserved for output                            */
  384.     UInt8                             scsiSCSIstatus;                /* <- Returned scsi device status                      */
  385.     SInt8                             scsiSenseResidual;            /* <- Autosense residual length                      */
  386.     UInt16                             scsiReserved5;                /* <-     reserved for output                             */
  387.     long                             scsiDataResidual;            /* <- Returned Transfer residual length              */
  388.     CDB                             scsiCDB;                    /* -> Actual CDB or pointer to CDB                  */
  389.     long                             scsiTimeout;                /* -> Timeout value (Time Mgr format) (CAM timeout) */
  390.     BytePtr                         scsiReserved5pt5;            /* -> Reserved                                        */
  391.     UInt16                             scsiReserved5pt6;            /* -> Reserved                                        */
  392.     UInt16                             scsiIOFlags;                /* -> additional I/O flags                               */
  393.     UInt8                             scsiTagAction;                /* -> What to do for tag queuing                       */
  394.     UInt8                             scsiReserved6;                /* ->     reserved for input                             */
  395.     UInt16                             scsiReserved7;                /* ->     reserved for input                             */
  396.     UInt16                             scsiSelectTimeout;            /* -> Select timeout value                             */
  397.     UInt8                             scsiDataType;                /* -> Data description type (i.e. buffer, TIB, S/G)    */
  398.     UInt8                             scsiTransferType;            /* -> Transfer type (i.e. Blind vs Polled)             */
  399.     UInt32                             scsiReserved8;                /* ->     reserved for input                             */
  400.     UInt32                             scsiReserved9;                /* ->     reserved for input                             */
  401.     UInt16                             scsiHandshake[8];            /* -> handshaking points (null term'd)    */
  402.     UInt32                             scsiReserved10;                /* ->     reserved for input                             */
  403.     UInt32                             scsiReserved11;                /* ->   reserved for input                            */
  404.     struct SCSI_IO *                scsiCommandLink;            /* -> Ptr to the next PB in linked cmd chain         */
  405.  
  406.     UInt8                             scsiSIMpublics[8];            /* ->     reserved for input to 3rd-party SIMs        */
  407.     UInt8                             scsiAppleReserved6[8];        /* ->    reserved for input                              */
  408.  
  409.                                                                 /* XPT layer privates (for old-API emulation) */
  410.  
  411.     UInt16                             scsiCurrentPhase;            /* <- phase upon completing old call                  */
  412.     short                             scsiSelector;                /* -> selector specified in old calls                  */
  413.     OSErr                             scsiOldCallResult;            /* <- result of old call                              */
  414.     UInt8                             scsiSCSImessage;            /* <- Returned scsi device message (for SCSIComplete)*/
  415.     UInt8                             XPTprivateFlags;            /* <> various flags                                   */
  416.     UInt8                             XPTextras[12];                /*                                                    */
  417. };
  418. typedef struct SCSI_IO                    SCSI_IO;
  419.  
  420. typedef SCSI_IO                         SCSIExecIOPB;
  421. /* Bus inquiry PB */
  422.  
  423. struct SCSIBusInquiryPB {
  424.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  425.     short                             scsiReserved1;                /* ->     reserved for input                */
  426.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  427.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  428.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  429.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  430.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  431.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  432.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  433.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  434.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  435.     long                             scsiReserved3;                /* reserved                                */
  436.  
  437.     UInt16                             scsiEngineCount;            /* <- Number of engines on HBA                         */
  438.     UInt16                             scsiMaxTransferType;        /* <- Number of transfer types for this HBA            */
  439.  
  440.     UInt32                             scsiDataTypes;                /* <- which data types are supported by this SIM     */
  441.  
  442.     UInt16                             scsiIOpbSize;                /* <- Size of SCSI_IO PB for this SIM/HBA             */
  443.     UInt16                             scsiMaxIOpbSize;            /* <- Size of max SCSI_IO PB for all SIM/HBAs         */
  444.  
  445.     UInt32                             scsiFeatureFlags;            /* <- Supported features flags field                 */
  446.  
  447.     UInt8                             scsiVersionNumber;            /* <- Version number for the SIM/HBA                 */
  448.     UInt8                             scsiHBAInquiry;                /* <- Mimic of INQ byte 7 for the HBA                 */
  449.     UInt8                             scsiTargetModeFlags;        /* <- Flags for target mode support                 */
  450.     UInt8                             scsiScanFlags;                /* <- Scan related feature flags                     */
  451.  
  452.     UInt32                             scsiSIMPrivatesPtr;            /* <- Ptr to SIM private data area                     */
  453.     UInt32                             scsiSIMPrivatesSize;        /* <- Size of SIM private data area                 */
  454.     UInt32                             scsiAsyncFlags;                /* <- Event cap. for Async Callback                 */
  455.  
  456.     UInt8                             scsiHiBusID;                /* <- Highest path ID in the subsystem              */
  457.     UInt8                             scsiInitiatorID;            /* <- ID of the HBA on the SCSI bus                 */
  458.     UInt16                             scsiBIReserved0;            /*                                                    */
  459.  
  460.     UInt32                             scsiBIReserved1;            /* <-                                                  */
  461.     UInt32                             scsiFlagsSupported;            /* <- which scsiFlags are supported                 */
  462.  
  463.     UInt16                             scsiIOFlagsSupported;        /* <- which scsiIOFlags are supported                 */
  464.     UInt16                             scsiWeirdStuff;                /* <-                                                 */
  465.     UInt16                             scsiMaxTarget;                /* <- maximum Target number supported                 */
  466.     UInt16                             scsiMaxLUN;                    /* <- maximum Logical Unit number supported         */
  467.  
  468.     char                             scsiSIMVendor[16];            /* <- Vendor ID of SIM (or XPT if bus<FF)         */
  469.     char                             scsiHBAVendor[16];            /* <- Vendor ID of the HBA                         */
  470.     char                             scsiControllerFamily[16];    /* <- Family of SCSI Controller                 */
  471.     char                             scsiControllerType[16];        /* <- Specific Model of SCSI Controller used     */
  472.  
  473.     char                             scsiXPTversion[4];            /* <- version number of XPT                         */
  474.     char                             scsiSIMversion[4];            /* <- version number of SIM                         */
  475.     char                             scsiHBAversion[4];            /* <- version number of HBA                         */
  476.  
  477.     UInt8                             scsiHBAslotType;            /* <- type of "slot" that this HBA is in            */
  478.     UInt8                             scsiHBAslotNumber;            /* <- slot number of this HBA                         */
  479.     UInt16                             scsiSIMsRsrcID;                /* <- resource ID of this SIM                         */
  480.  
  481.     UInt16                             scsiBIReserved3;            /* <-                                                 */
  482.     UInt16                             scsiAdditionalLength;        /* <- additional BusInquiry PB len                    */
  483. };
  484. typedef struct SCSIBusInquiryPB            SCSIBusInquiryPB;
  485. /* Abort SIM Request PB */
  486.  
  487. struct SCSIAbortCommandPB {
  488.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  489.     short                             scsiReserved1;                /* ->     reserved for input                */
  490.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  491.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  492.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  493.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  494.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  495.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  496.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  497.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  498.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  499.     long                             scsiReserved3;                /* reserved                                */
  500.     SCSI_IO *                        scsiIOptr;                    /* Pointer to the PB to abort            */
  501. };
  502. typedef struct SCSIAbortCommandPB        SCSIAbortCommandPB;
  503. /* Terminate I/O Process Request PB */
  504.  
  505. struct SCSITerminateIOPB {
  506.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  507.     short                             scsiReserved1;                /* ->     reserved for input                */
  508.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  509.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  510.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  511.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  512.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  513.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  514.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  515.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  516.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  517.     long                             scsiReserved3;                /* reserved                                */
  518.     SCSI_IO *                        scsiIOptr;                    /* Pointer to the PB to terminate         */
  519. };
  520. typedef struct SCSITerminateIOPB        SCSITerminateIOPB;
  521. /* Reset SCSI Bus PB */
  522.  
  523. struct SCSIResetBusPB {
  524.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  525.     short                             scsiReserved1;                /* ->     reserved for input                */
  526.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  527.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  528.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  529.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  530.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  531.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  532.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  533.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  534.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  535.     long                             scsiReserved3;                /* reserved                                */
  536. };
  537. typedef struct SCSIResetBusPB            SCSIResetBusPB;
  538. /* Reset SCSI Device PB */
  539.  
  540. struct SCSIResetDevicePB {
  541.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  542.     short                             scsiReserved1;                /* ->     reserved for input                */
  543.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  544.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  545.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  546.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  547.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  548.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  549.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  550.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  551.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  552.     long                             scsiReserved3;                /* reserved                                */
  553. };
  554. typedef struct SCSIResetDevicePB        SCSIResetDevicePB;
  555. /* Release SIM Queue PB */
  556.  
  557. struct SCSIReleaseQPB {
  558.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  559.     short                             scsiReserved1;                /* ->     reserved for input                */
  560.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  561.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  562.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  563.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  564.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  565.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  566.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  567.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  568.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  569.     long                             scsiReserved3;                /* reserved                                */
  570. };
  571. typedef struct SCSIReleaseQPB            SCSIReleaseQPB;
  572. /* SCSI Get Virtual ID Info PB */
  573.  
  574. struct SCSIGetVirtualIDInfoPB {
  575.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  576.     short                             scsiReserved1;                /* ->     reserved for input                */
  577.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  578.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  579.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  580.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  581.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  582.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  583.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  584.     Ptr                             scsiDriverStorage;            /* <> Ptr for driver private use        */
  585.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  586.     long                             scsiReserved3;                /* reserved                                */
  587.     UInt16                             scsiOldCallID;                /* -> SCSI ID of device in question     */
  588.     Boolean                         scsiExists;                    /* <- true if device exists             */
  589.     SInt8                             filler;
  590. };
  591. typedef struct SCSIGetVirtualIDInfoPB    SCSIGetVirtualIDInfoPB;
  592. /* Create/Lookup/Remove RefNum for Device PB */
  593.  
  594. struct SCSIDriverPB {
  595.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  596.     short                             scsiReserved1;                /* ->     reserved for input                */
  597.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  598.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  599.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  600.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  601.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  602.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  603.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  604.     Ptr                             scsiDriverStorage;            /* <> Ptr for driver private use        */
  605.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  606.     long                             scsiReserved3;                /* reserved                                */
  607.     short                             scsiDriver;                    /* -> DriverRefNum, For SetDriver, <- For GetNextDriver */
  608.     UInt16                             scsiDriverFlags;            /* <> Details of driver/device             */
  609.     DeviceIdent                     scsiNextDevice;                /* <- DeviceIdent of the NEXT Item in the list  */
  610. };
  611. typedef struct SCSIDriverPB                SCSIDriverPB;
  612. /* Load Driver PB */
  613.  
  614. struct SCSILoadDriverPB {
  615.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  616.     short                             scsiReserved1;                /* ->     reserved for input                */
  617.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  618.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  619.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  620.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  621.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  622.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  623.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  624.     Ptr                             scsiDriverStorage;            /* <> Ptr for driver private use        */
  625.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  626.     long                             scsiReserved3;                /* reserved                                */
  627.     short                             scsiLoadedRefNum;            /* <- SIM returns refnum of driver         */
  628.     Boolean                         scsiDiskLoadFailed;            /* -> if true, indicates call after failure to load */
  629.     SInt8                             filler;
  630. };
  631. typedef struct SCSILoadDriverPB            SCSILoadDriverPB;
  632.  
  633. /* Defines for the scsiTransferType field */
  634.  
  635. enum {
  636.     scsiTransferBlind            = 0,
  637.     scsiTransferPolled            = 1
  638. };
  639.  
  640.  
  641. enum {
  642.     scsiErrorBase                = -7936
  643. };
  644.  
  645.  
  646. enum {
  647.     scsiRequestInProgress        = 1,                            /* 1     = PB request is in progress             */
  648.                                                                 /* Execution failed  00-2F */
  649.     scsiRequestAborted            = scsiErrorBase + 2,            /* -7934 = PB request aborted by the host         */
  650.     scsiUnableToAbort            = scsiErrorBase + 3,            /* -7933 = Unable to Abort PB request             */
  651.     scsiNonZeroStatus            = scsiErrorBase + 4,            /* -7932 = PB request completed with an err     */
  652.     scsiUnused05                = scsiErrorBase + 5,            /* -7931 =                                      */
  653.     scsiUnused06                = scsiErrorBase + 6,            /* -7930 =                                      */
  654.     scsiUnused07                = scsiErrorBase + 7,            /* -7929 =                                      */
  655.     scsiUnused08                = scsiErrorBase + 8,            /* -7928 =                                      */
  656.     scsiUnableToTerminate        = scsiErrorBase + 9,            /* -7927 = Unable to Terminate I/O PB req         */
  657.     scsiSelectTimeout            = scsiErrorBase + 10,            /* -7926 = Target selection timeout             */
  658.     scsiCommandTimeout            = scsiErrorBase + 11,            /* -7925 = Command timeout                      */
  659.     scsiIdentifyMessageRejected    = scsiErrorBase + 12,            /* -7924 =                                      */
  660.     scsiMessageRejectReceived    = scsiErrorBase + 13,            /* -7923 = Message reject received                 */
  661.     scsiSCSIBusReset            = scsiErrorBase + 14,            /* -7922 = SCSI bus reset sent/received         */
  662.     scsiParityError                = scsiErrorBase + 15,            /* -7921 = Uncorrectable parity error occured     */
  663.     scsiAutosenseFailed            = scsiErrorBase + 16,            /* -7920 = Autosense: Request sense cmd fail     */
  664.     scsiUnused11                = scsiErrorBase + 17,            /* -7919 =                                      */
  665.     scsiDataRunError            = scsiErrorBase + 18,            /* -7918 = Data overrun/underrun error          */
  666.     scsiUnexpectedBusFree        = scsiErrorBase + 19,            /* -7917 = Unexpected BUS free                     */
  667.     scsiSequenceFailed            = scsiErrorBase + 20,            /* -7916 = Target bus phase sequence failure     */
  668.     scsiWrongDirection            = scsiErrorBase + 21,            /* -7915 = Data phase was in wrong direction     */
  669.     scsiUnused16                = scsiErrorBase + 22,            /* -7914 =                                      */
  670.     scsiBDRsent                    = scsiErrorBase + 23,            /* -7913 = A SCSI BDR msg was sent to target     */
  671.     scsiTerminated                = scsiErrorBase + 24,            /* -7912 = PB request terminated by the host     */
  672.     scsiNoNexus                    = scsiErrorBase + 25,            /* -7911 = Nexus is not established             */
  673.     scsiCDBReceived                = scsiErrorBase + 26,            /* -7910 = The SCSI CDB has been received         */
  674.                                                                 /* Couldn't begin execution  30-3F */
  675.     scsiTooManyBuses            = scsiErrorBase + 48,            /* -7888 = Register failed because we're full    */
  676.     scsiBusy                    = scsiErrorBase + 49,            /* -7887 = SCSI subsystem is busy                 */
  677.     scsiProvideFail                = scsiErrorBase + 50,            /* -7886 = Unable to provide requ. capability    */
  678.     scsiDeviceNotThere            = scsiErrorBase + 51,            /* -7885 = SCSI device not installed/there      */
  679.     scsiNoHBA                    = scsiErrorBase + 52,            /* -7884 = No HBA detected Error                 */
  680.     scsiDeviceConflict            = scsiErrorBase + 53,            /* -7883 = sorry, max 1 refNum per DeviceIdent     */
  681.     scsiNoSuchXref                = scsiErrorBase + 54,            /* -7882 = no such RefNum xref                     */
  682.     scsiQLinkInvalid            = scsiErrorBase + 55,            /* -7881 = pre-linked PBs not supported            */
  683.                                                                 /*   (The QLink field was nonzero)                */
  684.                                                                 /* Parameter errors  40-7F */
  685.     scsiPBLengthError            = scsiErrorBase + 64,            /* -7872 = (scsiPBLength is insuf'ct/invalid     */
  686.     scsiFunctionNotAvailable    = scsiErrorBase + 65,            /* -7871 = The requ. func is not available      */
  687.     scsiRequestInvalid            = scsiErrorBase + 66,            /* -7870 = PB request is invalid                 */
  688.     scsiBusInvalid                = scsiErrorBase + 67,            /* -7869 = Bus ID supplied is invalid              */
  689.     scsiTIDInvalid                = scsiErrorBase + 68,            /* -7868 = Target ID supplied is invalid         */
  690.     scsiLUNInvalid                = scsiErrorBase + 69,            /* -7867 = LUN supplied is invalid              */
  691.     scsiIDInvalid                = scsiErrorBase + 70,            /* -7866 = The initiator ID is invalid          */
  692.     scsiDataTypeInvalid            = scsiErrorBase + 71,            /* -7865 = scsiDataType requested not supported */
  693.     scsiTransferTypeInvalid        = scsiErrorBase + 72,            /* -7864 = scsiTransferType field is too high     */
  694.     scsiCDBLengthInvalid        = scsiErrorBase + 73            /* -7863 = scsiCDBLength field is too big         */
  695. };
  696.  
  697. /* New errors for SCSI Family         */
  698.  
  699. enum {
  700.     scsiUnused74                = scsiErrorBase + 74,            /* -7862 =                                          */
  701.     scsiUnused75                = scsiErrorBase + 75,            /* -7861 =                                         */
  702.     scsiBadDataLength            = scsiErrorBase + 76,            /* -7860 = a zero data length in PB             */
  703.     scsiPartialPrepared            = scsiErrorBase + 77,            /* -7859 = could not do full prepare mem for I/O*/
  704.     scsiInvalidMsgType            = scsiErrorBase + 78,            /* -7858 = Invalid message type (internal)        */
  705.     scsiUnused79                = scsiErrorBase + 79,            /* -7857 =                                           */
  706.     scsiBadConnID                = scsiErrorBase + 80,            /* -7856 = Bad Connection ID                      */
  707.     scsiUnused81                = scsiErrorBase + 81,            /* -7855 =                                         */
  708.     scsiIOInProgress            = scsiErrorBase + 82,            /* -7854 = Can't close conn, IO in prog            */
  709.     scsiTargetReserved            = scsiErrorBase + 83,            /* -7853 = Target already reserved                */
  710.     scsiUnused84                = scsiErrorBase + 84,            /* -7852 =                                         */
  711.     scsiUnused85                = scsiErrorBase + 85,            /* -7851 =                                         */
  712.     scsiBadConnType                = scsiErrorBase + 86,            /* -7850 = Bad connection type                    */
  713.     scsiCannotLoadPlugin        = scsiErrorBase + 87            /* -7849 = No matching service category            */
  714. };
  715.  
  716. /* +++ */
  717. /*
  718.  * scsiFamilyInternalError and scsiPluginInternalError are intended to handle consistency check failures.
  719.  * For example, if the family stores a record on a lookaside queue, but does not find that record
  720.  * it can use this error to report this failure. SCSI Manager 4.3 uses dsIOCoreErr in a few places,
  721.  * but this is probably not the best error. In general, internal errors should be reported as bugs.
  722.  *
  723.  * The following range of errors is provided for third-party (non-Apple) SCSI SIM and device driver vendors.
  724.  * In general, they would be used for error conditions that are not covered by the standardized errors.
  725.  * They should not normally be conveyed to normal applications, but might be used for communication between
  726.  * a plug-in and a vendor-provided device driver (for example, to manage RAID hot-swapping).
  727.  *
  728.  * Note: I don't know how many SCSI errors are reserved in the error code architecture. Don't assume that
  729.  * we'll actually get sixteen, but we should reserve at least one.
  730.  */
  731.  
  732. enum {
  733.     scsiFamilyInternalError        = scsiErrorBase + 87,            /* -7849 = Internal consistency check failed    */
  734.     scsiPluginInternalError        = scsiErrorBase + 88,            /* -7848 = Internal consistency check failed    */
  735.     scsiVendorSpecificErrorBase    = scsiErrorBase + 128,            /* ??    = Start of third-party error range        */
  736.     scsiVendorSpecificErrorCount = 16                            /* Number of third-party errors                    */
  737. };
  738.  
  739. /* --- */
  740.  
  741. enum {
  742.     scsiExecutionErrors            = scsiErrorBase,
  743.     scsiNotExecutedErrors        = scsiTooManyBuses,
  744.     scsiParameterErrors            = scsiPBLengthError
  745. };
  746.  
  747. /* Defines for the scsiResultFlags field */
  748.  
  749. enum {
  750.     scsiSIMQFrozen                = 0x0001,                        /* The SIM queue is frozen w/this err            */
  751.     scsiAutosenseValid            = 0x0002,                        /* Autosense data valid for target              */
  752.     scsiBusNotFree                = 0x0004                        /* At time of callback, SCSI bus is not free    */
  753. };
  754.  
  755. /* Defines for the bit numbers of the scsiFlags field in the PB header for the SCSIExecIO function */
  756.  
  757. enum {
  758.     kbSCSIDisableAutosense        = 29,                            /* Disable auto sense feature                     */
  759.     kbSCSIFlagReservedA            = 28,                            /*                                              */
  760.     kbSCSIFlagReserved0            = 27,                            /*                                              */
  761.     kbSCSICDBLinked                = 26,                            /* The PB contains a linked CDB                    */
  762.     kbSCSIQEnable                = 25,                            /* Target queue actions are enabled                */
  763.     kbSCSICDBIsPointer            = 24,                            /* The CDB field contains a pointer                */
  764.     kbSCSIFlagReserved1            = 23,                            /*                                                 */
  765.     kbSCSIInitiateSyncData        = 22,                            /* Attempt Sync data xfer and SDTR                */
  766.     kbSCSIDisableSyncData        = 21,                            /* Disable sync, go to async                    */
  767.     kbSCSISIMQHead                = 20,                            /* Place PB at the head of SIM Q                */
  768.     kbSCSISIMQFreeze            = 19,                            /* Return the SIM Q to frozen state                */
  769.     kbSCSISIMQNoFreeze            = 18,                            /* Disallow SIM Q freezing                        */
  770.     kbSCSIDoDisconnect            = 17,                            /* Definitely do disconnect                        */
  771.     kbSCSIDontDisconnect        = 16,                            /* Definitely don't disconnect                    */
  772.     kbSCSIDataReadyForDMA        = 15,                            /* Data buffer(s) are ready for DMA                */
  773.     kbSCSIFlagReserved3            = 14,                            /*                                                 */
  774.     kbSCSIDataPhysical            = 13,                            /* SG/Buffer data ptrs are physical                */
  775.     kbSCSISensePhysical            = 12,                            /* Autosense buffer ptr is physical                */
  776.     kbSCSIFlagReserved5            = 11,                            /*                                                 */
  777.     kbSCSIFlagReserved6            = 10,                            /*                                                 */
  778.     kbSCSIFlagReserved7            = 9,                            /*                                                 */
  779.     kbSCSIFlagReserved8            = 8,                            /*                                                 */
  780.     kbSCSIDataBufferValid        = 7,                            /* Data buffer valid                            */
  781.     kbSCSIStatusBufferValid        = 6,                            /* Status buffer valid                             */
  782.     kbSCSIMessageBufferValid    = 5,                            /* Message buffer valid                            */
  783.     kbSCSIFlagReserved9            = 4                                /*                                              */
  784. };
  785.  
  786. /* Defines for the bit masks of the scsiFlags field */
  787.  
  788. enum {
  789.     scsiDirectionMask            = (long)0xC0000000,                /* Data direction mask                        */
  790.     scsiDirectionNone            = (long)0xC0000000,                /* Data direction (11: no data)                */
  791.     scsiDirectionReserved        = 0x00000000,                    /* Data direction (00: reserved)            */
  792.     scsiDirectionOut            = (long)0x80000000,                /* Data direction (10: DATA OUT)            */
  793.     scsiDirectionIn                = 0x40000000,                    /* Data direction (01: DATA IN)                */
  794.     scsiDisableAutosense        = 0x20000000,                    /* Disable auto sense feature                */
  795.     scsiFlagReservedA            = 0x10000000,                    /*                                             */
  796.     scsiFlagReserved0            = 0x08000000,                    /*                                             */
  797.     scsiCDBLinked                = 0x04000000,                    /* The PB contains a linked CDB                */
  798.     scsiQEnable                    = 0x02000000,                    /* Target queue actions are enabled            */
  799.     scsiCDBIsPointer            = 0x01000000,                    /* The CDB field contains a pointer            */
  800.     scsiFlagReserved1            = 0x00800000,                    /*                                             */
  801.     scsiInitiateSyncData        = 0x00400000,                    /* Attempt Sync data xfer and SDTR            */
  802.     scsiDisableSyncData            = 0x00200000,                    /* Disable sync, go to async                */
  803.     scsiSIMQHead                = 0x00100000,                    /* Place PB at the head of SIM Q            */
  804.     scsiSIMQFreeze                = 0x00080000,                    /* Return the SIM Q to frozen state            */
  805.     scsiSIMQNoFreeze            = 0x00040000,                    /* Disallow SIM Q freezing                    */
  806.     scsiDoDisconnect            = 0x00020000,                    /* Definitely do disconnect                    */
  807.     scsiDontDisconnect            = 0x00010000,                    /* Definitely don't disconnect                */
  808.     scsiDataReadyForDMA            = 0x00008000,                    /* Data buffer(s) are ready for DMA            */
  809.     scsiFlagReserved3            = 0x00004000,                    /*  */
  810.     scsiDataPhysical            = 0x00002000,                    /* SG/Buffer data ptrs are physical            */
  811.     scsiSensePhysical            = 0x00001000,                    /* Autosense buffer ptr is physical            */
  812.     scsiFlagReserved5            = 0x00000800,                    /*                                          */
  813.     scsiFlagReserved6            = 0x00000400,                    /*                                             */
  814.     scsiFlagReserved7            = 0x00000200,                    /*                                             */
  815.     scsiFlagReserved8            = 0x00000100                    /*                                             */
  816. };
  817.  
  818. /* bit masks for the scsiIOFlags field in SCSIExecIOPB */
  819.  
  820. enum {
  821.     scsiNoParityCheck            = 0x0002,                        /* disable parity checking                             */
  822.     scsiDisableSelectWAtn        = 0x0004,                        /* disable select w/Atn                              */
  823.     scsiSavePtrOnDisconnect        = 0x0008,                        /* do SaveDataPointer upon Disconnect msg             */
  824.     scsiNoBucketIn                = 0x0010,                        /* don’t bit bucket in during this I/O                 */
  825.     scsiNoBucketOut                = 0x0020,                        /* don’t bit bucket out during this I/O             */
  826.     scsiDisableWide                = 0x0040,                        /* disable wide transfer negotiation                 */
  827.     scsiInitiateWide            = 0x0080,                        /* initiate wide transfer negotiation                 */
  828.     scsiRenegotiateSense        = 0x0100,                        /* renegotiate sync/wide before issuing autosense     */
  829.     scsiDisableDiscipline        = 0x0200,                        /* disable parameter checking on SCSIExecIO calls    */
  830.     scsiIOFlagReserved0080        = 0x0080,                        /*                                                  */
  831.     scsiIOFlagReserved8000        = 0x8000                        /*                                                     */
  832. };
  833.  
  834. /* Defines for the Bus Inquiry PB fields. */
  835. /* scsiHBAInquiry field bits */
  836.  
  837. enum {
  838.     scsiBusMDP                    = 0x80,                            /* Supports Modify Data Pointer message                        */
  839.     scsiBusWide32                = 0x40,                            /* Supports 32 bit wide SCSI                                */
  840.     scsiBusWide16                = 0x20,                            /* Supports 16 bit wide SCSI                                */
  841.     scsiBusSDTR                    = 0x10,                            /* Supports Sync Data Transfer Req message                    */
  842.     scsiBusLinkedCDB            = 0x08,                            /* Supports linked CDBs                                        */
  843.     scsiBusTagQ                    = 0x02,                            /* Supports tag queue message                                */
  844.     scsiBusSoftReset            = 0x01                            /* Supports soft reset                                        */
  845. };
  846.  
  847. /* Defines for the scsiDataType field */
  848.  
  849. enum {
  850.     scsiDataBuffer                = 0,                            /* single contiguous buffer supplied                  */
  851.     scsiDataTIB                    = 1,                            /* TIB supplied (ptr in scsiDataPtr)                 */
  852.     scsiDataSG                    = 2,                            /* scatter/gather list supplied                      */
  853.     scsiDataIOTable                = 3                                /*#(7/11/95) Prepared by Block Storage              */
  854. };
  855.  
  856. /* scsiDataTypes field bits  */
  857. /*    bits 0->15 Apple-defined, 16->30 3rd-party unique, 31 = reserved */
  858.  
  859. enum {
  860.     scsiBusDataTIB                = (1 << scsiDataTIB),            /* TIB supplied (ptr in scsiDataPtr)        */
  861.     scsiBusDataBuffer            = (1 << scsiDataBuffer),        /* single contiguous buffer supplied         */
  862.     scsiBusDataSG                = (1 << scsiDataSG),            /* scatter/gather list supplied             */
  863.     scsiBusDataIOTable            = (1 << scsiDataIOTable),        /* (2/6/95) Prepare Memory for IO*/
  864.     scsiBusDataReserved            = (long)0x80000000                /*                                           */
  865. };
  866.  
  867. /* scsiScanFlags field bits */
  868.  
  869. enum {
  870.     scsiBusScansDevices            = 0x80,                            /* Bus scans for and maintains device list            */
  871.     scsiBusScansOnInit            = 0x40,                            /* Bus scans performed at power-up/reboot            */
  872.     scsiBusLoadsROMDrivers        = 0x20                            /* may load ROM drivers to support targets             */
  873. };
  874.  
  875. /* scsiFeatureFlags field bits */
  876.  
  877. enum {
  878.     scsiBusLVD                    = 0x00000400,                    /* HBA is Low Voltage Differential Bus            */
  879.     scsiBusUltra3SCSI            = 0x00000200,                    /* HBA supports Ultra3 SCSI                        */
  880.     scsiBusUltra2SCSI            = 0x00000100,                    /* HBA supports Ultra2 SCSI                        */
  881.     scsiBusInternalExternalMask    = 0x000000C0,                    /* bus internal/external mask                    */
  882.     scsiBusInternalExternalUnknown = 0x00000000,                /* not known whether bus is inside or outside     */
  883.     scsiBusInternalExternal        = 0x000000C0,                    /* bus goes inside and outside the box             */
  884.     scsiBusInternal                = 0x00000080,                    /* bus goes inside the box                         */
  885.     scsiBusExternal                = 0x00000040,                    /* bus goes outside the box                     */
  886.     scsiBusCacheCoherentDMA        = 0x00000020,                    /* DMA is cache coherent                         */
  887.     scsiBusOldCallCapable        = 0x00000010,                    /* SIM is old call capable                         */
  888.     scsiBusUltraSCSI            = 0x00000008,                    /* HBA supports Ultra SCSI                        */
  889.     scsiBusDifferential            = 0x00000004,                    /* Single Ended (0) or Differential (1)         */
  890.     scsiBusFastSCSI                = 0x00000002,                    /* HBA supports fast SCSI                         */
  891.     scsiBusDMAavailable            = 0x00000001                    /* DMA is available                             */
  892. };
  893.  
  894. /* scsiWeirdStuff field bits */
  895.  
  896. enum {
  897.     scsiOddDisconnectUnsafeRead1 = 0x0001,                        /* Disconnects on odd byte boundries are unsafe with DMA and/or blind reads */
  898.     scsiOddDisconnectUnsafeWrite1 = 0x0002,                        /* Disconnects on odd byte boundries are unsafe with DMA and/or blind writes */
  899.     scsiBusErrorsUnsafe            = 0x0004,                        /* Non-handshaked delays or disconnects during blind transfers may cause a crash */
  900.     scsiRequiresHandshake        = 0x0008,                        /* Non-handshaked delays or disconnects during blind transfers may cause data corruption */
  901.     scsiTargetDrivenSDTRSafe    = 0x0010,                        /* Targets which initiate synchronous negotiations are supported */
  902.     scsiOddCountForPhysicalUnsafe = 0x0020,                        /* If using physical addrs all counts must be even, and disconnects must be on even boundries */
  903.     scsiAbortCmdFixed            = 0x0040,                        /* Set if abort command is fixed to properly make callbacks */
  904.     scsiMeshACKTimingFixed        = 0x0080                        /* Set if bug allowing Mesh to release ACK prematurely is fixed */
  905. };
  906.  
  907. /* scsiHBAslotType values */
  908.  
  909. enum {
  910.     scsiMotherboardBus            = 0x00,                            /* A built in Apple supplied bus                     */
  911.     scsiNuBus                    = 0x01,                            /* A SIM on a NuBus card                             */
  912.     scsiPDSBus                    = 0x03,                            /*    "  on a PDS card                                */
  913.     scsiPCIBus                    = 0x04,                            /*    "  on a PCI bus card                            */
  914.     scsiPCMCIABus                = 0x05,                            /*    "  on a PCMCIA card                            */
  915.     scsiFireWireBridgeBus        = 0x06                            /*    "  connected through a FireWire bridge        */
  916. };
  917.  
  918. /* Defines for the scsiDriverFlags field (in SCSIDriverPB) */
  919.  
  920. enum {
  921.     scsiDeviceSensitive            = 0x0001,                        /* Only driver should access this device                */
  922.     scsiDeviceNoOldCallAccess    = 0x0002                        /* no old call access to this device                     */
  923. };
  924.  
  925. /*  SIMInitInfo PB */
  926. /* directions are for SCSIRegisterBus call ( -> parm, <- result)             */
  927.  
  928. struct SIMInitInfo {
  929.     Ptr                             SIMstaticPtr;                /* <- alloc. ptr to the SIM's static vars                 */
  930.     long                             staticSize;                    /* -> num bytes SIM needs for static vars                 */
  931.     SIMInitUPP                         SIMInit;                    /* -> pointer to the SIM init routine                     */
  932.     SIMActionUPP                     SIMAction;                    /* -> pointer to the SIM action routine                 */
  933.     SCSIInterruptUPP                 SIM_ISR;                    /*       reserved                                             */
  934.     SCSIInterruptUPP                 SIMInterruptPoll;            /* -> pointer to the SIM interrupt poll routine            */
  935.     SIMActionUPP                     NewOldCall;                    /* -> pointer to the SIM NewOldCall routine                */
  936.     UInt16                             ioPBSize;                    /* -> size of SCSI_IO_PBs required for this SIM            */
  937.     Boolean                         oldCallCapable;                /* -> true if this SIM can handle old-API calls            */
  938.     UInt8                             simInfoUnused1;                /*       reserved                                            */
  939.     long                             simInternalUse;                /* xx not affected or viewed by XPT                        */
  940.     SCSIUPP                         XPT_ISR;                    /*    reserved                                            */
  941.     SCSIUPP                         EnteringSIM;                /* <- ptr to the EnteringSIM routine                    */
  942.     SCSIUPP                         ExitingSIM;                    /* <- ptr to the ExitingSIM routine                        */
  943.     SCSIMakeCallbackUPP             MakeCallback;                /* <- the XPT layer’s SCSIMakeCallback routine            */
  944.     UInt16                             busID;                        /* <- bus number for the registered bus                    */
  945.     UInt8                             simSlotNumber;                /* <- Magic cookie to place in scsiHBASlotNumber (PCI)    */
  946.     UInt8                             simSRsrcID;                    /* <- Magic cookie to place in scsiSIMsRsrcID     (PCI)    */
  947.     Ptr                             simRegEntry;                /* -> The SIM's RegEntryIDPtr                     (PCI)    */
  948. };
  949. typedef struct SIMInitInfo                SIMInitInfo;
  950. /* Glue between SCSI calls and SCSITrap format */
  951.  
  952. enum {
  953.     xptSCSIAction                = 0x0001,
  954.     xptSCSIRegisterBus            = 0x0002,
  955.     xptSCSIDeregisterBus        = 0x0003,
  956.     xptSCSIReregisterBus        = 0x0004,
  957.     xptSCSIKillXPT                = 0x0005,                        /* kills Mini-XPT after transition */
  958.     xptSCSIInitialize            = 0x000A                        /* Initialize the SCSI manager */
  959. };
  960.  
  961. /*
  962.  * SCSI bus status. These values are returned by the SCSI target in the status phase.
  963.  * They are not related to Macintosh status values (except that values other than
  964.  * scsiStatusGood will result in scsiResult set to scsiNonZeroStatus).
  965.  */
  966.  
  967. enum {
  968.     scsiStatGood                = 0x00,                            /* Good Status*/
  969.     scsiStatCheckCondition        = 0x02,                            /* Check Condition*/
  970.     scsiStatConditionMet        = 0x04,                            /* Condition Met*/
  971.     scsiStatBusy                = 0x08,                            /* Busy*/
  972.     scsiStatIntermediate        = 0x10,                            /* Intermediate*/
  973.     scsiStatIntermedMet            = 0x14,                            /* Intermediate - Condition Met*/
  974.     scsiStatResvConflict        = 0x18,                            /* Reservation conflict*/
  975.     scsiStatTerminated            = 0x22,                            /* Command terminated*/
  976.     scsiStatQFull                = 0x28                            /* Queue full*/
  977. };
  978.  
  979. /* SCSI messages*/
  980.  
  981. enum {
  982.     kCmdCompleteMsg                = 0,
  983.     kExtendedMsg                = 1,                            /* 0x01*/
  984.     kSaveDataPointerMsg            = 2,                            /* 0x02*/
  985.     kRestorePointersMsg            = 3,                            /* 0x03*/
  986.     kDisconnectMsg                = 4,                            /* 0x04*/
  987.     kInitiatorDetectedErrorMsg    = 5,                            /* 0x05*/
  988.     kAbortMsg                    = 6,                            /* 0x06*/
  989.     kMsgRejectMsg                = 7,                            /* 0x07*/
  990.     kNoOperationMsg                = 8,                            /* 0x08*/
  991.     kMsgParityErrorMsg            = 9,                            /* 0x09*/
  992.     kLinkedCmdCompleteMsg        = 10,                            /* 0x0a*/
  993.     kLinkedCmdCompleteWithFlagMsg = 11,                            /* 0x0b*/
  994.     kBusDeviceResetMsg            = 12,                            /* 0x0c*/
  995.     kAbortTagMsg                = 13,                            /* 0x0d*/
  996.     kClearQueueMsg                = 14,                            /* 0x0e*/
  997.     kInitiateRecoveryMsg        = 15,                            /* 0x0f*/
  998.     kReleaseRecoveryMsg            = 16,                            /* 0x10*/
  999.     kTerminateIOProcessMsg        = 17,                            /* 0x11*/
  1000.     kSimpleQueueTag                = 0x20,                            /* 0x20*/
  1001.     kHeadOfQueueTagMsg            = 0x21,                            /* 0x21*/
  1002.     kOrderedQueueTagMsg            = 0x22,                            /* 0x22*/
  1003.     kIgnoreWideResidueMsg        = 0x23                            /* 0x23*/
  1004. };
  1005.  
  1006.  
  1007. /* moveq #kSCSIx, D0;  _SCSIAtomic */
  1008.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  1009.                                                                                             #pragma parameter __D0 SCSIAction(__A0)
  1010.                                                                                             #endif
  1011. EXTERN_API( OSErr )
  1012. SCSIAction                        (SCSI_PB *                parameterBlock)                        TWOWORDINLINE(0x7001, 0xA089);
  1013.  
  1014.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  1015.                                                                                             #pragma parameter __D0 SCSIRegisterBus(__A0)
  1016.                                                                                             #endif
  1017. EXTERN_API( OSErr )
  1018. SCSIRegisterBus                    (SIMInitInfo *            parameterBlock)                        TWOWORDINLINE(0x7002, 0xA089);
  1019.  
  1020.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  1021.                                                                                             #pragma parameter __D0 SCSIDeregisterBus(__A0)
  1022.                                                                                             #endif
  1023. EXTERN_API( OSErr )
  1024. SCSIDeregisterBus                (SCSI_PB *                parameterBlock)                        TWOWORDINLINE(0x7003, 0xA089);
  1025.  
  1026.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  1027.                                                                                             #pragma parameter __D0 SCSIReregisterBus(__A0)
  1028.                                                                                             #endif
  1029. EXTERN_API( OSErr )
  1030. SCSIReregisterBus                (SIMInitInfo *            parameterBlock)                        TWOWORDINLINE(0x7004, 0xA089);
  1031.  
  1032.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  1033.                                                                                             #pragma parameter __D0 SCSIKillXPT(__A0)
  1034.                                                                                             #endif
  1035. EXTERN_API( OSErr )
  1036. SCSIKillXPT                        (SIMInitInfo *            parameterBlock)                        TWOWORDINLINE(0x7005, 0xA089);
  1037.  
  1038.  
  1039.  
  1040. #if PRAGMA_STRUCT_ALIGN
  1041.     #pragma options align=reset
  1042. #elif PRAGMA_STRUCT_PACKPUSH
  1043.     #pragma pack(pop)
  1044. #elif PRAGMA_STRUCT_PACK
  1045.     #pragma pack()
  1046. #endif
  1047.  
  1048. #ifdef PRAGMA_IMPORT_OFF
  1049. #pragma import off
  1050. #elif PRAGMA_IMPORT
  1051. #pragma import reset
  1052. #endif
  1053.  
  1054. #ifdef __cplusplus
  1055. }
  1056. #endif
  1057.  
  1058. #endif /* __SCSI__ */
  1059.  
  1060.